﻿/*
#**************************************************************************
#  openSIS is a student information system for public and non-public 
#  schools from Open Solutions for Education, Inc. web: www.os4ed.com
#
#  openSIS is  web-based, open source, and comes packed with features that 
#  include student demographic info, scheduling, grade book, attendance, 
#  report cards, eligibility, transcripts, parent portal, 
#  student portal and more.   
#
#  Visit the openSIS web site at http://www.opensis.com to learn more.
#  If you have question regarding this system or the license, please send 
#  an email to info@os4ed.com.
#
#  This program is released under the terms of the GNU General Public License  
#  as  published by the Free Software Foundation, version 2 of the License. 
#  See license.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#**************************************************************************** 

*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.UI.HtmlControls;
using OpenSISInstall;
using OpenSIS.OpenSISWCFServiceReference;
using OSISDynamicTranslation;
using OpenSISStaffDropDownList;

public partial class Staff_EditStaffInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string sCulture = Session["MLCulture"].ToString();
        SISInstall SISInstall = new SISInstall();
       // SchoolBL schoolAdd = new SchoolBL();

        OpenSISWCFServiceInstallationClient InstallBL = new OpenSISWCFServiceInstallationClient();
        DataTable dtDateFormat = InstallBL.getdateformat();
        InstallBL.Close();
        if (dtDateFormat.Rows.Count > 0)
        {
            SISInstall.CalenderDateFormat = dtDateFormat.Rows[0][0].ToString();
        }
        CalDobDate.Format = SISInstall.CalenderDateFormat.ToString().Trim();
        CalJoinDate.Format = SISInstall.CalenderDateFormat.ToString().Trim();
        calExtCertDate.Format = SISInstall.CalenderDateFormat.ToString().Trim();
        CalExtCertExpDt.Format = SISInstall.CalenderDateFormat.ToString().Trim();
        CalExtLeftDate.Format = SISInstall.CalenderDateFormat.ToString().Trim();
        CalExCertDateEdit.Format = SISInstall.CalenderDateFormat.ToString().Trim();
        CalExCertExpDateEdit.Format = SISInstall.CalenderDateFormat.ToString().Trim();
        if (txtStaPass.Text != "")
        {
            hdnPasswrd.Value = txtStaPass.Text.ToString();
        }
        if (Session["StaffImage"] != null)
        {
            // imgStudentPhoto.Src = Session["StudentImage"].ToString();
            //divPhotoUpload.Attributes.Clear();
            divPhotoUpload.Style.Add("background-image", "url(" + Session["StaffImage"].ToString().Replace("~", "..") + ")");
        }
        if (!Page.IsPostBack)
        {
            if (Session["CertTable"] != null)
            {
                Session["CertTable"] = null;
            }
            hdnStfId.Value = Session["StaffId"].ToString();
            PopulateCategoryTree();
            tvCategories.Nodes[0].Select();
            PopulateAllControls();
            PopulateStaffDetails();           
            lblCatName.Text = "<div class='heading_bevelline'>" + tvCategories.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
            if (rbtnDisability.SelectedIndex != -1)
            {
                if (rbtnDisability.SelectedItem.Value == "N")
                {
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divDisability').style.display='none'", true);
                }
            }
        }
        chkSame.Attributes.Add("onclick", "CheckSameAddress()");
        ibtnEditcert.Attributes.Add("onclick", "return GridCheckBoxSelectioneditstaff('" + sCulture + "')");
    }
    public void PopulateCategoryTree()
    {
        DynamicTranslation DTL = new DynamicTranslation();
        string langto = Session["MLUICulture"].ToString();
        try
        {
            tvCategories.Nodes.Clear();
            TreeNode TreeNodeDemoInfo = new TreeNode();

            string s = "Demographic Information";
            string t = DTL.Translate(s, "en", langto);
            TreeNodeDemoInfo.Text = t + "&nbsp;&nbsp;&nbsp;&nbsp;";
            TreeNodeDemoInfo.Value = Convert.ToString("0");
            tvCategories.Nodes.Add(TreeNodeDemoInfo);

            s = "Address and Contact";
            t = DTL.Translate(s, "en", langto);
            TreeNode TreeNodeAddCont = new TreeNode();
            TreeNodeAddCont.Text = t + "&nbsp;&nbsp;&nbsp;&nbsp;";
            TreeNodeAddCont.Value = Convert.ToString("1");
            tvCategories.Nodes.Add(TreeNodeAddCont);

            s = "School Information";
            t = DTL.Translate(s, "en", langto);
            TreeNode TreeNodeSchoolInfo = new TreeNode();
            TreeNodeSchoolInfo.Text = t + "&nbsp;&nbsp;&nbsp;&nbsp;";
            TreeNodeSchoolInfo.Value = Convert.ToString("2");
            tvCategories.Nodes.Add(TreeNodeSchoolInfo);

            s = "Certification Information";
            t = DTL.Translate(s, "en", langto);
            TreeNode TreeNodeCertificate = new TreeNode();
            TreeNodeCertificate.Text = t + "&nbsp;&nbsp;&nbsp;&nbsp;";
            TreeNodeCertificate.Value = Convert.ToString("3");
            tvCategories.Nodes.Add(TreeNodeCertificate);
            tvCategories.ExpandAll();
        }
        catch
        { }
    }
    protected void tvCategories_SelectedNodeChanged(object sender, EventArgs e)
    {       
        try
        {
            if (txtStaPass.Text != "")
            {
                hdnPasswrd.Value = txtStaPass.Text.ToString();
            }
            string CatValue = tvCategories.SelectedNode.Value;
            mvCategories.ActiveViewIndex = Convert.ToInt32(CatValue);
            lblCatName.Text = "<div class='heading_bevelline'>" + tvCategories.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
            int category = Convert.ToInt32(tvCategories.SelectedNode.Value);
            hdnCatId.Value = Convert.ToString(category);
            if (category > 0)
            {
                btnPrev.Visible = true;
            }
            if (category + 1 == tvCategories.Nodes.Count)
            {
                btnNext.Visible = false;
                btnUpdate.Visible = true;
            }
            if (category + 1 < tvCategories.Nodes.Count)
            {
                btnNext.Visible = true;
                btnUpdate.Visible = false;
            }
            if (category == 0)
            {
                btnPrev.Visible = false;
            }
            if (mvCategories.ActiveViewIndex == 0)
            {
                btnNext.ValidationGroup = "vgDemoInfo";
                if (rbtnDisability.SelectedItem.Value == "N")
                {
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divDisability').style.display='none'", true);
                }
            }
            if (mvCategories.ActiveViewIndex == 1)
            {
                btnNext.ValidationGroup = "vgAddrInfo";
            }
            if (mvCategories.ActiveViewIndex == 2)
            {
                btnNext.ValidationGroup = "vgSchlInfo";
                txtStaPass.Attributes.Add("value", hdnPasswrd.Value);
                //if (txtLibCrdNo.Text == "")
                //{
                //    txtLibCrdNo.Text = STABL.GenerateRandomNumber(5);
                //}
                if (rbtnOpenAccess.SelectedIndex != -1)
                {
                    if (rbtnOpenAccess.SelectedItem.Value == "N")
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divOpenAcces').style.display='none'", true);
                    }
                }
                if (rbtnLibAcc.SelectedIndex != -1)
                {
                    if (rbtnLibAcc.SelectedItem.Value == "N")
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divOpenAcces').style.display='block';document.getElementById('divlib').style.display='none'", true);
                    }
                }
            }
            if (mvCategories.ActiveViewIndex == 3)
            {
                if (Session["CertTable"] != null)
                {
                    DataTable dt = (DataTable)Session["CertTable"];
                    gvCertficates.DataSource = dt;
                    gvCertficates.DataBind();
                }
            }
        }
        catch
        {
        }
    }
    public void PopulateAllControls()
    {
        StaffDropDown STABL = new StaffDropDown();
        try
        {
            STABL.PopulateEthnicity(ref ddlEthnicity,Convert.ToInt32(Session["SchoolID"]));
            STABL.PopulateLanguage(ref ddlLang);
            STABL.PopulateLanguage(ref ddlSecnLang);
            STABL.PopulateLanguage(ref ddlThrdLang);
            STABL.PopulateState(ref ddlSecnState);
            STABL.PopulateState(ref ddlState);
            STABL.PopulateStaffType(ref ddlStaffTyp);
            STABL.PopulateSchools(ref ddlSchools);
            STABL.PopulateSchoolsCheckbox(ref chkschools);
            STABL.PopulateGender(ref ddlGender);
            STABL.PopulateSalutation(ref ddlSalutation);
            STABL.PopulateSuffix(ref ddlSuffix);
            STABL.PopulateRelationShip(ref ddlRelation);
            STABL.PopulateStatus(ref ddlStatus);
            STABL.PopulateLibraryClass(ref ddlLibCLass);
            STABL.PopulateSecretquestion(ref ddlsecrQues);
        }
        catch
        {
        }
        finally
        {
            STABL = null;
        }

    }    
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
       // Function Func = new Function();
       // StaffBL STABL = new StaffBL();
        try
        {
            string FirstName = txtStaFrstNam.Text.Replace("'", "''");
            string MiddleName = txtStaMidlNam.Text.Replace("'", "''");
            string LastName = txtStalstNam.Text.Replace("'", "''");
            string Gender = ddlGender.SelectedItem.Value;
            string DOB = txtDOB.Text.Replace("'", "''");
            string Language = ddlLang.SelectedItem.Value;
            string Secondlang = ddlSecnLang.SelectedItem.Value;
            string Thirdlang = ddlThrdLang.SelectedItem.Value;
            string Ethnicity = ddlEthnicity.SelectedItem.Value;
            string Salutation = ddlSalutation.SelectedItem.Value;
            string Suffix = ddlSuffix.SelectedItem.Value;
            string Disability = rbtnDisability.SelectedItem.Value;
            string Disabilitydesc = txtDisDesc.Text.Replace("'", "''");
            string StaffIdNumber = txtStaffId.Text.Replace("'", "''");
            string Alternateid = txtAltrntId.Text.Replace("'", "''");
            string PrimaryAddress1 = txtAdd1.Text.Replace("'", "''");
            string PrimaryAddress2 = txtAdd2.Text.Replace("'", "''");
            string PrimaryCity = txtCity.Text.Replace("'", "''");
            string PrimaryState = ddlState.SelectedItem.Value;
            string PrimaryZip = txtZip.Text.Replace("'", "''");
            string SecondaryAddress1 = txtSecnAdd1.Text.Replace("'", "''");
            string SecondaryAddress2 = txtSecnAdd2.Text.Replace("'", "''");
            string SecondaryCity = txtSecnCity.Text.Replace("'", "''");
            string SecondaryState = ddlSecnState.SelectedItem.Value;
            string SecondaryZip = txtSecnZip.Text.Replace("'", "''");
            string PoBox = txtPObox.Text.Replace("'", "''");
            string HomePhone = txtHomePhn.Text.Replace("'", "''");
            string MobilPhon = txtMobPhn.Text.Replace("'", "''");
            string Officphon = txtOffcPhn.Text.Replace("'", "''");
            string WorkEmail = txtWrkEmail.Text.Replace("'", "''");
            string Personalemail = txtPersEmail.Text.Replace("'", "''");
            string Emrgnemail = txtEmrgnEmail.Text.Replace("'", "''");
            string Emrgnfirstnam = txtEmrgnFrstNam.Text.Replace("'", "''");
            string EmrgnHomePhon = txtEmrgnHomPhn.Text.Replace("'", "''");
            string Emrgnlastnam = txtEmrgnLastNam.Text.Replace("'", "''");
            string Emrgnrelationship = ddlRelation.SelectedItem.Value;
            string EmrgnWorkPhon = txtEmrgnWrkPhn.Text.Replace("'", "''");
            string EmrgnMobilePhon = txtEmrgnMobPhn.Text.Replace("'", "''");
            int HomeSchoolId = Convert.ToInt32(Session["SchoolID"].ToString());
            string JoiningDate = txtDateJoin.Text.Replace("'", "''");
            string LeftDate = txtleftdate.Text.Replace("'", "''");
            string Jobtitle = txtJobTitle.Text.Replace("'", "''");
            string StaffType = ddlStaffTyp.SelectedItem.Value;
            string OpensisAcces = rbtnOpenAccess.SelectedItem.Value;
            //string Role = ddlOpenProf.SelectedItem.Value;
            string Username = txtStaUsrnam.Text.Replace("'", "''");
            string Password = hdnPasswrd.Value.Replace("'", "''");
            //string SecretQuestn = txtSecQues.Text.Replace("'", "''");
            string SecretQuestn = ddlsecrQues.SelectedItem.Value;
            string SecretAnswr = txtSecrAnsr.Text.Replace("'", "''");
            string Status = ddlStatus.SelectedItem.Value.Replace("'", "''");
            string LibraryAccess = "";
            if (rbtnLibAcc.SelectedIndex != -1)
            {
                LibraryAccess = rbtnLibAcc.SelectedItem.Value;
            }
            string LibraryCard = txtLibCrdNo.Text.Replace("'", "''");
            string LibraryClass = ddlLibCLass.SelectedItem.Value;
            //Staff Details 
            //string StaffId = string InsertStaffDetails();
            int StaffId = Convert.ToInt32(hdnStfId.Value);
            
            OpenSISWCFServiceStaffClient SPCClientSD = new OpenSISWCFServiceStaffClient();
            SPCClientSD.UpdateStaffDetails(Language,Gender,Ethnicity,FirstName,MiddleName,LastName,DOB,"",StaffIdNumber,Alternateid,Salutation,Suffix,Secondlang,Thirdlang,Disability,Disabilitydesc,StaffId);
            SPCClientSD.Close();
            
            OpenSISWCFServiceStaffClient SPCClientSAD = new OpenSISWCFServiceStaffClient();
            SPCClientSAD.UpdateStaffaddressDetails(PrimaryAddress1,PrimaryAddress2,PrimaryCity,PrimaryState,PrimaryZip,SecondaryAddress1,SecondaryAddress2,SecondaryCity,SecondaryState,SecondaryZip,PoBox,StaffId);
            SPCClientSAD.Close();

            OpenSISWCFServiceStaffClient SPCClientSPD = new OpenSISWCFServiceStaffClient();
            SPCClientSPD.UpdateStaffphoneDetails(HomePhone,MobilPhon,Officphon,WorkEmail,Personalemail,StaffId);
            SPCClientSPD.Close();

            //Staff Access Details insert Commented for table related confusion

            OpenSISWCFServiceStaffClient SPCClientSSJD = new OpenSISWCFServiceStaffClient();
            SPCClientSSJD.UpdateStaffschooljoinDetails(HomeSchoolId,JoiningDate,LeftDate,Jobtitle,StaffType,StaffId);
            SPCClientSSJD.Close();

            string schoolname = "";
            foreach (ListItem cBox in chkschools.Items)
            {
                if (cBox.Selected)
                {
                    schoolname += cBox.Value + ",";
                }
            }

            
           // schoolname = schoolname.LastIndexOf(",").ToString().Replace(",","");

            string SchoolAccess = schoolname;

            OpenSISWCFServiceStaffClient SPCClientSACCD = new OpenSISWCFServiceStaffClient();
            SPCClientSACCD.UpdateStaffaccessDetails(Username,Password,SecretQuestn,SecretAnswr,OpensisAcces,SchoolAccess,StaffId);
            SPCClientSACCD.Close();

            //STABL.SchoolName = schoolname;
            OpenSISWCFServiceStaffClient SPCClientSLA = new OpenSISWCFServiceStaffClient();
            int libacc = SPCClientSLA.CheckLibAccessbyStaffid(StaffId);
            SPCClientSLA.Close();

            if (rbtnLibAcc.SelectedIndex != -1)
            {
                if (rbtnLibAcc.SelectedIndex != -1)
                {
                    OpenSISWCFServiceStaffClient SPCClientSLAD = new OpenSISWCFServiceStaffClient();
                    if (libacc != 0)
                    {
                        SPCClientSLAD.UpdateStafflibaccessDetails(LibraryCard,LibraryClass,Status,LibraryAccess,StaffId);
                    }
                    else
                    {
                        SPCClientSLAD.InsertStaffLibraryDetails(StaffId,LibraryCard,LibraryClass,Status,LibraryAccess);
                    }
                    SPCClientSLAD.Close();
                }
            }

            OpenSISWCFServiceStaffClient SPCClientSED = new OpenSISWCFServiceStaffClient();
            SPCClientSED.UpdateStaffemergencyDetails(Emrgnfirstnam,Emrgnlastnam,Emrgnrelationship,EmrgnHomePhon,EmrgnMobilePhon,EmrgnWorkPhon,Emrgnrelationship,StaffId);
            SPCClientSED.Close();

            if (Session["CertTable"] != null)
            {
                DataTable dtcertificates = (DataTable)Session["CertTable"];
                for (int i = 0; i < dtcertificates.Rows.Count; i++)
                {
                    //HiddenField hdnedit = (HiddenField)gvCertficates.Rows[i].FindControl("hdnedit");                      
                    string CertDate = dtcertificates.Rows[i]["stf_cert_dt"].ToString();
                    string CertCode = dtcertificates.Rows[i]["stf_cert_cd"].ToString();
                    string CertShortName = dtcertificates.Rows[i]["stf_cert_short_nm"].ToString();
                    string CertName = dtcertificates.Rows[i]["stf_cert_nm"].ToString();
                    string Primarycert = dtcertificates.Rows[i]["stf_pri_cert_ind"].ToString();
                    string CertExpirDate = dtcertificates.Rows[i]["stf_cert_exp_dt"].ToString();
                    string CertDescription = dtcertificates.Rows[i]["stf_cert_desc"].ToString();
                    string Certificateid = dtcertificates.Rows[i]["stf_cert_id"].ToString();
                    OpenSISWCFServiceStaffClient SPCClientSCRTD = new OpenSISWCFServiceStaffClient();
                    if (dtcertificates.Rows[i]["tempid"].ToString() == "Edit")
                    {
                        SPCClientSCRTD.UpdateStaffcertificationDetails(CertDate,CertExpirDate,CertCode,CertShortName,CertName,Primarycert,CertDescription,StaffId,Certificateid);
                    }
                    if (dtcertificates.Rows[i]["tempid"].ToString() == "Added")
                    {
                        SPCClientSCRTD.InsertStaffCertificateDetails(StaffId,CertDate,CertExpirDate,CertCode,CertShortName,CertName,Primarycert,"",CertDescription);
                    }
                    SPCClientSCRTD.Close();
                }
            }
            string PhotoUrl = "";
            if (Session["StaffImage"] != null)
            {
                PhotoUrl = Session["StaffImage"].ToString().Replace("~", "..");
            }
            HomeSchoolId = Convert.ToInt32(Session["SchoolID"]);

            OpenSISWCFServiceStaffClient SPCClientSPURL = new OpenSISWCFServiceStaffClient();
            DataTable dtpic = SPCClientSPURL.PopulatestaffPhoto(StaffId,HomeSchoolId);
            SPCClientSPURL.Close();
            if (Session["StaffImage"] != null)
            {
                PhotoUrl = Session["StaffImage"].ToString().Replace("~", "..");
            }
            else
            {
                if (dtpic.Rows.Count > 0)
                {
                   PhotoUrl = dtpic.Rows[0]["name"].ToString();
                }
                else
                {
                    PhotoUrl = "../App_Themes/main/images/no_pic.png";
                }
            }

            OpenSISWCFServiceStaffClient SPCClientSPSAVEORUPDATE = new OpenSISWCFServiceStaffClient();
            if (dtpic.Rows.Count == 0)
            {
                SPCClientSPSAVEORUPDATE.savestaffphoto(StaffId,HomeSchoolId,PhotoUrl);
            }
            else
            {
                SPCClientSPSAVEORUPDATE.Updatestaffphoto(StaffId,HomeSchoolId,PhotoUrl);
            }
            SPCClientSPSAVEORUPDATE.Close();
            if (Session["WorkingImage"] != null)
            {
                string uploadedimage = "~/Garbage Image/" + Session["WorkingImage"].ToString();
                System.IO.File.Delete(Server.MapPath(uploadedimage));
                Session["WorkingImage"] = null;
            }
            if (Session["StaffImage"] != null)
            {
                Session["StaffImage"] = null;
            }
            Session["CertTable"] = null;
            //Func.ResetFormControlValues(this.Page);
            //gvCertficates.Columns.Clear();
            Session["StaffId"] = StaffId;
            Session["DirectView"] = "DV";
            Response.Redirect("StaffInfo.aspx");
        }
        catch
        {
        }
        finally
        {
           
        }
    }
    protected void btnNext_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            if (txtStaPass.Text != "")
            {
                hdnPasswrd.Value = txtStaPass.Text.ToString();
            }
            int category = Convert.ToInt32(tvCategories.SelectedNode.Value);
            tvCategories.Nodes[category + 1].Select();
            mvCategories.ActiveViewIndex = category + 1;
            lblCatName.Text = "<div class='heading_bevelline'>" + tvCategories.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
            hdnCatId.Value = Convert.ToString(category);
            if (category + 1 > 0)
            {
                btnPrev.Visible = true;
            }
            if (category + 2 == tvCategories.Nodes.Count)
            {
                btnNext.Visible = false;
                btnUpdate.Visible = true;
            }
            if (mvCategories.ActiveViewIndex == 0)
            {
                btnNext.ValidationGroup = "vgDemoInfo";
            }
            if (mvCategories.ActiveViewIndex == 1)
            {
                btnNext.ValidationGroup = "vgAddrInfo";
            }
            if (mvCategories.ActiveViewIndex == 2)
            {
                btnNext.ValidationGroup = "vgSchlInfo";
                //cvlChkSchl.ClientValidationFunction = "CheckboxValidation";
                txtStaPass.Attributes.Add("value", hdnPasswrd.Value);
                //if (txtLibCrdNo.Text == "")
                //{
                //    txtLibCrdNo.Text = STABL.GenerateRandomNumber(5);
                //}
                if (rbtnOpenAccess.SelectedIndex != -1)
                {
                    if (rbtnOpenAccess.SelectedItem.Value == "N")
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divOpenAcces').style.display='none'", true);
                    }
                }
                if (rbtnLibAcc.SelectedIndex != -1)
                {
                    if (rbtnLibAcc.SelectedItem.Value == "N")
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divlib').style.display='none'", true);
                    }
                }
            }
            if (mvCategories.ActiveViewIndex == 3)
            {
                if (Session["CertTable"] != null)
                {
                    DataTable dt = (DataTable)Session["CertTable"];
                    gvCertficates.DataSource = dt;
                    gvCertficates.DataBind();
                }
            }
        }
        catch (Exception ex)
        {
            string error = ex.ToString();
        }
    }
    protected void btnPrev_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            if (txtStaPass.Text != "")
            {
                hdnPasswrd.Value = txtStaPass.Text.ToString();
            }
            int category = Convert.ToInt32(tvCategories.SelectedNode.Value);
            tvCategories.Nodes[category - 1].Select();
            mvCategories.ActiveViewIndex = category - 1;
            lblCatName.Text = "<div class='heading_bevelline'>" + tvCategories.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
            if (category - 1 == 0)
            {
                btnPrev.Visible = false;
            }
            if (category < tvCategories.Nodes.Count)
            {
                btnNext.Visible = true;
                btnUpdate.Visible = false;
            }
            if (mvCategories.ActiveViewIndex == 0)
            {
                btnNext.ValidationGroup = "vgDemoInfo";
                if (rbtnDisability.SelectedItem.Value == "N")
                {
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divDisability').style.display='none'", true);
                }
            }
            if (mvCategories.ActiveViewIndex == 1)
            {
                btnNext.ValidationGroup = "vgAddrInfo";
            }
            if (mvCategories.ActiveViewIndex == 2)
            {
                btnNext.ValidationGroup = "vgSchlInfo";
                txtStaPass.Attributes.Add("value", hdnPasswrd.Value);
                if (rbtnOpenAccess.SelectedIndex != -1)
                {
                    if (rbtnOpenAccess.SelectedItem.Value == "N")
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divOpenAcces').style.display='none'", true);
                    }
                }
                if (rbtnLibAcc.SelectedIndex != -1)
                {
                    if (rbtnLibAcc.SelectedItem.Value == "N")
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divlib').style.display='none'", true);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            string error = ex.ToString();
        }
    }
    protected void btnSaveCert_Click(object sender, EventArgs e)
    {
        try
        {
            int StaffId = Convert.ToInt32(hdnStfId.Value);
            OpenSISWCFServiceStaffClient SPCClientPPCert = new OpenSISWCFServiceStaffClient();
            DataTable dt = SPCClientPPCert.PopulateCertification(StaffId);
            SPCClientPPCert.Close();

            if (dt.Rows.Count == 0)
            {
                //hdnBlankgrid.Value = "Filled";
                if (Session["CertTable"] == null)
                {
                    DataTable dtcert = new DataTable();
                    dtcert.Columns.Add("stf_cert_dt");
                    dtcert.Columns.Add("stf_cert_exp_dt");
                    dtcert.Columns.Add("stf_cert_cd");
                    dtcert.Columns.Add("stf_cert_short_nm");
                    dtcert.Columns.Add("stf_cert_nm");
                    dtcert.Columns.Add("stf_pri_cert_ind");
                    dtcert.Columns.Add("stf_cert_desc");
                    dtcert.Columns.Add("stf_cert_id");
                    dtcert.Columns.Add("stf_id");
                    dtcert.Columns.Add("tempid");
                    DataRow dr = dtcert.NewRow();
                    dr["stf_cert_id"] = "1";
                    dr["stf_cert_dt"] = txtCertDate.Text;
                    dr["stf_cert_exp_dt"] = txtCertExpDat.Text;
                    dr["stf_cert_cd"] = txtCertCode.Text;
                    dr["stf_cert_short_nm"] = txtCertShrtName.Text;
                    dr["stf_cert_nm"] = txtCertName.Text;
                    if (rbtnPrimrCert.SelectedIndex != -1)
                    {
                        dr["stf_pri_cert_ind"] = rbtnPrimrCert.SelectedItem.Value;
                    }
                    dr["stf_cert_desc"] = txtCertDesc.Text;
                    dr["tempid"] = "Added";
                    dtcert.Rows.Add(dr);
                    gvCertficates.DataSource = dtcert;
                    gvCertficates.DataBind();
                    Session.Add("CertTable", dtcert);
                }
                else
                {
                    DataTable dtcertrpt = (DataTable)Session["CertTable"];
                    DataRow dr = dtcertrpt.NewRow();
                    int rows = dtcertrpt.Rows.Count - 1;
                    int lastcertid = Convert.ToInt32(dtcertrpt.Rows[rows]["stf_cert_id"]);
                    dr["stf_cert_id"] = lastcertid + 1;
                    dr["stf_cert_dt"] = txtCertDate.Text;
                    dr["stf_cert_exp_dt"] = txtCertExpDat.Text;
                    dr["stf_cert_cd"] = txtCertCode.Text;
                    dr["stf_cert_short_nm"] = txtCertShrtName.Text;
                    dr["stf_cert_nm"] = txtCertName.Text;
                    if (rbtnPrimrCert.SelectedIndex != -1)
                    {
                        dr["stf_pri_cert_ind"] = rbtnPrimrCert.SelectedItem.Value;
                    }
                    dr["stf_cert_desc"] = txtCertDesc.Text;
                    dr["tempid"] = "Added";
                    dtcertrpt.Rows.Add(dr);
                    gvCertficates.DataSource = dtcertrpt;
                    gvCertficates.DataBind();
                    Session.Add("CertTable", dtcertrpt);
                }
            }
            else
            {
                if (Session["CertTable"] == null)
                {
                    dt.Columns.Add("tempid");
                    DataRow dr = dt.NewRow();
                    int rows = dt.Rows.Count - 1;
                    int lastcertid = Convert.ToInt32(dt.Rows[rows]["stf_cert_id"]);
                    dr["stf_cert_id"] = lastcertid + 1;
                    dr["stf_cert_dt"] = txtCertDate.Text;
                    dr["stf_cert_exp_dt"] = txtCertExpDat.Text;
                    dr["stf_cert_cd"] = txtCertCode.Text;
                    dr["stf_cert_short_nm"] = txtCertShrtName.Text;
                    dr["stf_cert_nm"] = txtCertName.Text;
                    if (rbtnPrimrCert.SelectedIndex != -1)
                    {
                        dr["stf_pri_cert_ind"] = rbtnPrimrCert.SelectedItem.Value;
                    }
                    dr["stf_cert_desc"] = txtCertDesc.Text;
                    dr["tempid"] = "Added";
                    dt.Rows.Add(dr);
                    gvCertficates.DataSource = dt;
                    gvCertficates.DataBind();
                    Session.Add("CertTable", dt);
                }
                else
                {
                    DataTable dtcertaftredit = (DataTable)Session["CertTable"];
                    DataRow dr = dtcertaftredit.NewRow();
                    int rows = dtcertaftredit.Rows.Count - 1;
                    int lastcertid = Convert.ToInt32(dtcertaftredit.Rows[rows]["stf_cert_id"]);
                    dr["stf_cert_id"] = lastcertid + 1;
                    dr["stf_cert_dt"] = txtCertDate.Text;
                    dr["stf_cert_exp_dt"] = txtCertExpDat.Text;
                    dr["stf_cert_cd"] = txtCertCode.Text;
                    dr["stf_cert_short_nm"] = txtCertShrtName.Text;
                    dr["stf_cert_nm"] = txtCertName.Text;
                    if (rbtnPrimrCert.SelectedIndex != -1)
                    {
                        dr["stf_pri_cert_ind"] = rbtnPrimrCert.SelectedItem.Value;
                    }
                    dr["stf_cert_desc"] = txtCertDesc.Text;
                    dr["tempid"] = "Added";
                    dtcertaftredit.Rows.Add(dr);
                    gvCertficates.DataSource = dtcertaftredit;
                    gvCertficates.DataBind();
                    Session.Add("CertTable", dtcertaftredit);
                }
            }
            txtCertDate.Text = "";
            txtCertExpDat.Text = "";
            txtCertCode.Text = "";
            txtCertShrtName.Text = "";
            txtCertName.Text = "";
            rbtnPrimrCert.SelectedIndex = -1;
            txtCertDesc.Text = "";
        }
        catch (Exception ex)
        {
            string error = ex.ToString();
        }
    }
    protected void rbtnOpenAccess_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (rbtnOpenAccess.SelectedValue == "Y")
        {
            // rfvOpenProf.Enabled = true;
            rfvPass.Enabled = true;
            rfvSecretQues.Enabled = true;
            rfvSecrAnsr.Enabled = true;
            cvlChkSchl.Enabled = true;
            rfvUsernam.Enabled = true;
            rfvLibAcces.Enabled = true;
            //divlib.Style.Add("display","block");
            //pnlOpenAcces.Visible = true;
            txtStaPass.Text = "";
            txtStaUsrnam.Text = "";
            // txtSecQues.Text = "";
            ddlsecrQues.ClearSelection();
            txtSecrAnsr.Text = "";
            chkschools.ClearSelection();
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divlib').style.display='none'", true);
        }
        else
        {
            rfvPass.Enabled = false;
            rfvSecretQues.Enabled = false;
            rfvSecrAnsr.Enabled = false;
            cvlChkSchl.Enabled = false;
            rfvUsernam.Enabled = false;
            rfvLibAcces.Enabled = false;
            rbtnLibAcc.SelectedIndex = -1;
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divOpenAcces').style.display='none'", true);
        }
    }
    protected void rbtnLibAcc_SelectedIndexChanged(object sender, EventArgs e)
    {        
        if (rbtnLibAcc.SelectedValue == "Y")
        {
            rfvStatus.Enabled = true;
            rfvCardNo.Enabled = true;
            rfvLibCLas.Enabled = true;
            //pnlLib.Visible = true;
            OpenSISWCFServiceStaffClient SpcClientRand = new OpenSISWCFServiceStaffClient();
            txtLibCrdNo.Text = SpcClientRand.GenerateRandomNumber();
            SpcClientRand.Close();
        }
        else
        {
            rfvStatus.Enabled = false;
            rfvCardNo.Enabled = false;
            rfvLibCLas.Enabled = false;
            //pnlLib.Visible = false;
            txtLibCrdNo.Text = "";
            ddlLibCLass.ClearSelection();
            ddlStatus.ClearSelection();
            ddlLibCLass.Items.FindByValue("0").Selected = true;
            ddlStatus.Items.FindByValue("0").Selected = true;
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divlib').style.display='none'", true);
        }
    }
    protected void gvCertficates_RowDataBound(object sender, GridViewRowEventArgs e)
    {        
        SISInstall SISinstall = new SISInstall();
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lblPrimryCert = (Label)e.Row.FindControl("lblPrimryCert");
            Label lblCertDate = (Label)e.Row.FindControl("lblCertDate");
            Label lblCertExpDate = (Label)e.Row.FindControl("lblCertExpDate");
            HiddenField hdnstafffid = (HiddenField)e.Row.FindControl("hdnstafffid");
            HiddenField hdnedit = (HiddenField)e.Row.FindControl("hdnedit");
            HiddenField hdncertid = (HiddenField)e.Row.FindControl("hdncertid");
            CheckBox chk = (CheckBox)e.Row.FindControl("chk");
            Label lblNotAdded = (Label)e.Row.FindControl("lblNotAdded");
            if (Session["CertTable"] != null)
            {
                DataTable dt = (DataTable)Session["CertTable"];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    hdnedit.Value = dt.Rows[i]["tempid"].ToString();
                }
            }
            if (hdnstafffid.Value != "")
            {
                Session["StaffId"] = Convert.ToInt32(hdnstafffid.Value);
            }
            OpenSISWCFServiceStaffClient SPCClientCert = new OpenSISWCFServiceStaffClient();
            DataTable dtcert = SPCClientCert.PopulateCertification(Convert.ToInt32(Session["StaffID"]));
            SPCClientCert.Close();
            if (hdncertid.Value == "")
            {
                chk.Visible = false;
                ibtnEditcert.Visible = false;
                lblNotAdded.Visible = true;
            }
            else
            {
                chk.Visible = true;
                ibtnEditcert.Visible = true;
                lblNotAdded.Visible = false;
            }
            if (lblCertDate.Text != "")
            {
                DateTime certdate = Convert.ToDateTime(lblCertDate.Text);
                lblCertDate.Text = certdate.Date.ToString(SISinstall.CalenderDateFormat);
            }
            if (lblCertExpDate.Text != "")
            {
                DateTime CertExpDate = Convert.ToDateTime(lblCertExpDate.Text);
                lblCertExpDate.Text = CertExpDate.Date.ToString(SISinstall.CalenderDateFormat);
            }
            if (lblPrimryCert.Text == "Y")
            {
                lblPrimryCert.Text = "Yes";
            }
            else if (lblPrimryCert.Text == "")
            {
                lblPrimryCert.Text = "";
            }
            else
            {
                lblPrimryCert.Text = "No";
            }
        }
    }
    public void PopulateStaffDetails()
    {
        //StaffBL STABL = new StaffBL();
        SISInstall SISinstall = new SISInstall();
        try
        {
            int SchoolId = Convert.ToInt32(Session["SchoolID"]);
            int StaffId = Convert.ToInt32(Session["StaffID"]);
            OpenSISWCFServiceStaffClient SPCClientS = new OpenSISWCFServiceStaffClient();
            DataTable dt = SPCClientS.PopulateStaffdetailsEdit(SchoolId, StaffId);
            SPCClientS.Close();

            txtStaffId.Text = dt.Rows[0]["staffidnumber"].ToString().Trim();
            txtAltrntId.Text = dt.Rows[0]["stf_alternate_id"].ToString().Trim();
            ddlSalutation.Text = dt.Rows[0]["stf_salutation"].ToString().Trim();
            ddlSalutation.Items.FindByValue(dt.Rows[0]["stf_salutation"].ToString().Trim()).Selected = true;
            txtStaFrstNam.Text = dt.Rows[0]["stf_first_nm"].ToString().Trim();
            txtStaMidlNam.Text = dt.Rows[0]["stf_middle_nm"].ToString().Trim();
            txtStalstNam.Text = dt.Rows[0]["stf_last_nm"].ToString().Trim();
            ddlSuffix.Items.FindByValue(dt.Rows[0]["stf_suffix"].ToString().Trim()).Selected = true;
            ddlGender.Items.FindByValue(dt.Rows[0]["gender_id"].ToString().Trim()).Selected = true;
            ddlEthnicity.Items.FindByValue(dt.Rows[0]["eth_id"].ToString().Trim()).Selected = true;
            ddlLang.Items.FindByValue(dt.Rows[0]["language_id"].ToString().Trim()).Selected = true;
            ddlSecnLang.Items.FindByValue(dt.Rows[0]["stf_secondry_lang_id"].ToString().Trim()).Selected = true;
            ddlThrdLang.Items.FindByValue(dt.Rows[0]["stf_third_lang_id"].ToString().Trim()).Selected = true;
            rbtnDisability.Items.FindByValue(dt.Rows[0]["stf_disability"].ToString().Trim()).Selected = true;
            txtDisDesc.Text = dt.Rows[0]["stf_disability_desc"].ToString().Trim();
            txtAdd1.Text = dt.Rows[0]["stf_addr1_pri"].ToString().Trim();
            txtAdd2.Text = dt.Rows[0]["stf_addr2_pri"].ToString().Trim();
            txtCity.Text = dt.Rows[0]["stf_city_pri"].ToString().Trim();
            ddlState.Items.FindByValue(dt.Rows[0]["stf_st_pri"].ToString().Trim()).Selected = true;
            txtZip.Text = dt.Rows[0]["stf_zip_pri"].ToString().Trim();
            txtSecnAdd1.Text = dt.Rows[0]["stf_addr1_mail"].ToString().Trim();
            txtSecnAdd2.Text = dt.Rows[0]["stf_addr2_mail"].ToString().Trim();
            txtSecnCity.Text = dt.Rows[0]["stf_city_mail"].ToString().Trim();
            ddlSecnState.Items.FindByValue(dt.Rows[0]["stf_st_mail"].ToString().Trim()).Selected = true;
            txtSecnZip.Text = dt.Rows[0]["stf_zip_mail"].ToString().Trim();
            txtPObox.Text = dt.Rows[0]["stf_pobox_mail"].ToString().Trim();
            txtHomePhn.Text = dt.Rows[0]["stf_home_phn"].ToString().Trim();
            txtOffcPhn.Text = dt.Rows[0]["stf_offc_phn"].ToString().Trim();
            txtMobPhn.Text = dt.Rows[0]["stf_mobile_phn"].ToString().Trim();
            txtWrkEmail.Text = dt.Rows[0]["stf_wrk_email"].ToString().Trim();
            txtPersEmail.Text = dt.Rows[0]["stf_personal_email"].ToString().Trim();
            txtEmrgnFrstNam.Text = dt.Rows[0]["stf_emrgn_first_name"].ToString().Trim();
            txtEmrgnWrkPhn.Text = dt.Rows[0]["stf_emrgn_offc_phn"].ToString().Trim();
            txtEmrgnLastNam.Text = dt.Rows[0]["stf_emrgn_last_name"].ToString().Trim();
            txtEmrgnMobPhn.Text = dt.Rows[0]["stf_emrgn_mobile_phn"].ToString().Trim();
            txtEmrgnHomPhn.Text = dt.Rows[0]["stf_emrgn_home_phn"].ToString().Trim();
            txtEmrgnEmail.Text = dt.Rows[0]["stf_emrgn_email"].ToString().Trim();
            ddlRelation.Items.FindByValue(dt.Rows[0]["stf_emrgn_relationship"].ToString().Trim()).Selected = true;
            ddlStaffTyp.Items.FindByValue(dt.Rows[0]["stf_type_id"].ToString().Trim()).Selected = true;
            txtJobTitle.Text = dt.Rows[0]["stf_job_title"].ToString().Trim();
            txtDateJoin.Text = dt.Rows[0]["stf_hire_dt"].ToString().Trim();
            txtleftdate.Text = dt.Rows[0]["stf_term_dt"].ToString().Trim();
            ddlSchools.Items.FindByValue(dt.Rows[0]["sch_id"].ToString().Trim()).Selected = true;
            if (dt.Rows[0]["stf_opensis_access"].ToString().Trim() == "N")
            {
            }
            else
            {
                rfvPass.Enabled = true;
                rfvSecretQues.Enabled = true;
                rfvSecrAnsr.Enabled = true;
                cvlChkSchl.Enabled = true;
                rfvUsernam.Enabled = true;
                rfvLibAcces.Enabled = true;
                //pnlOpenAcces.Visible = true;
            }
            string id = dt.Rows[0]["school_access"].ToString().Trim();
            string[] b = id.Split(new char[] { ',' });
            for (int k = 0; k < b.Length; k++)
            {
                foreach (ListItem itm in chkschools.Items)
                {
                    if (itm.Value.ToLower() == b[k].Trim().ToLower())
                    {
                        itm.Selected = true;
                    }
                }
            }
            rbtnOpenAccess.Items.FindByValue(dt.Rows[0]["stf_opensis_access"].ToString().Trim()).Selected = true;
            txtStaUsrnam.Text = dt.Rows[0]["stf_user_nm"].ToString().Trim();
            hdnPasswrd.Value = dt.Rows[0]["stf_pwd"].ToString().Trim();
            //txtStaPass.Text = STABL.Password;
            txtStaPass.Attributes.Add("value", hdnPasswrd.Value);
            //txtSecQues.Text = STABL.SecretQuestn;
            ddlsecrQues.Items.FindByValue(dt.Rows[0]["stf_secret_ques"].ToString().Trim()).Selected = true;
            txtSecrAnsr.Text = dt.Rows[0]["stf_secret_ans"].ToString().Trim();
            if (dt.Rows[0]["stf_lib_access"].ToString().Trim() == "Y")
            {
                rfvStatus.Enabled = true;
                rfvCardNo.Enabled = true;
                rfvLibCLas.Enabled = true;
                //pnlLib.Visible = true;
            }
            else
            {
                //pnlLib.Visible = false;            
            }
            if (dt.Rows[0]["stf_lib_access"].ToString().Trim() != "")
            {
                rbtnLibAcc.Items.FindByValue(dt.Rows[0]["stf_lib_access"].ToString().Trim()).Selected = true;
            }
            if (dt.Rows[0]["stf_lib_class"].ToString().Trim() != "")
            {
                ddlLibCLass.Items.FindByValue(dt.Rows[0]["stf_lib_class"].ToString().Trim()).Selected = true;
            }
            txtLibCrdNo.Text = dt.Rows[0]["stf_lib_card_no"].ToString().Trim();
            if (dt.Rows[0]["stf_status"].ToString().Trim() != "")
            {
                ddlStatus.Items.FindByValue(dt.Rows[0]["stf_status"].ToString().Trim()).Selected = true;
            }
            DateTime dob = DateTime.Parse(dt.Rows[0]["stf_dob"].ToString().Trim());
            txtDOB.Text = dob.Date.ToString(SISinstall.CalenderDateFormat);
            DateTime joindate = DateTime.Parse(dt.Rows[0]["stf_hire_dt"].ToString().Trim());
            txtDateJoin.Text = joindate.Date.ToString(SISinstall.CalenderDateFormat);
            if (dt.Rows[0]["stf_term_dt"].ToString().Trim() != "")
            {
                DateTime enddate = DateTime.Parse(dt.Rows[0]["stf_term_dt"].ToString().Trim());
                txtleftdate.Text = enddate.Date.ToString(SISinstall.CalenderDateFormat);
            }
            else
            {
                txtleftdate.Text = dt.Rows[0]["stf_term_dt"].ToString().Trim();
            }

            OpenSISWCFServiceStaffClient SPCClientSt = new OpenSISWCFServiceStaffClient();
            DataTable dtcert = SPCClientSt.PopulateCertification(StaffId);
            SPCClientSt.Close();           
            if (dtcert.Rows.Count > 0)
            {
                gvCertficates.DataSource = dtcert;
                gvCertficates.DataBind();
            }
            else
            {
                DataTable dtcertblnk = new DataTable();
                dtcertblnk.Columns.Add("stf_id");
                dtcertblnk.Columns.Add("stf_cert_id");
                dtcertblnk.Columns.Add("stf_cert_dt");
                dtcertblnk.Columns.Add("stf_cert_exp_dt");
                dtcertblnk.Columns.Add("stf_cert_cd");
                dtcertblnk.Columns.Add("stf_cert_short_nm");
                dtcertblnk.Columns.Add("stf_cert_nm");
                dtcertblnk.Columns.Add("stf_pri_cert_ind");
                dtcertblnk.Columns.Add("stf_cert_desc");
                DataRow dr = dtcertblnk.NewRow();
                dr["stf_id"] = SPCClientSt;
                dr["stf_cert_id"] = "";
                dr["stf_cert_dt"] = "";
                dr["stf_cert_exp_dt"] = "";
                dr["stf_cert_cd"] = "";
                dr["stf_cert_short_nm"] = "";
                dr["stf_cert_nm"] = "";
                dr["stf_pri_cert_ind"] = "";
                dr["stf_cert_desc"] = "";
                dtcertblnk.Rows.Add(dr);
                gvCertficates.DataSource = dtcertblnk;
                gvCertficates.DataBind();
            }

            OpenSISWCFServiceStaffClient SPCClientStf = new OpenSISWCFServiceStaffClient();
            DataTable dtpic = SPCClientStf.PopulatestaffPhoto(StaffId,SchoolId);
            if (dtpic.Rows.Count > 0)
            {
                string PhotoUrl = dtpic.Rows[0]["name"].ToString();
                if (PhotoUrl != "")
                {
                    divPhotoUpload.Style.Add("background-image", "url(" + PhotoUrl + ")");
                }
            }
        }
        catch
        {
        }
        finally
        {           
        }
    }
    protected void ibtnEditcert_Click(object sender, ImageClickEventArgs e)
    {        
        SISInstall SISInstall = new SISInstall();
        for (int i = 0; i < gvCertficates.Rows.Count; i++)
        {
            CheckBox chk = (CheckBox)gvCertficates.Rows[i].FindControl("chk");
            HiddenField hdnstafffid = (HiddenField)gvCertficates.Rows[i].FindControl("hdnstafffid");
            HiddenField hdncertid = (HiddenField)gvCertficates.Rows[i].FindControl("hdncertid");
            Label lblCertName = (Label)gvCertficates.Rows[i].FindControl("lblCertName");
            Label lblCertShortName = (Label)gvCertficates.Rows[i].FindControl("lblCertShortName");
            Label lblCertCode = (Label)gvCertficates.Rows[i].FindControl("lblCertCode");
            Label lblCertDate = (Label)gvCertficates.Rows[i].FindControl("lblCertDate");
            Label lblCertExpDate = (Label)gvCertficates.Rows[i].FindControl("lblCertExpDate");
            Label lblPrimryCert = (Label)gvCertficates.Rows[i].FindControl("lblPrimryCert");
            Label lblCertDesc = (Label)gvCertficates.Rows[i].FindControl("lblCertDesc");
            HiddenField hdnPrimcert = (HiddenField)gvCertficates.Rows[i].FindControl("hdnPrimcert");
            if (chk.Checked)
            {
                Session["StaffId"] = hdnstafffid.Value.ToString();
                //Response.Redirect("EditStaffInfo.aspx");
                txtCerShrtNamEdit.Text = lblCertShortName.Text.ToString();
                txtCertFnameEdit.Text = lblCertName.Text.ToString();
                txtCertCodeEdit.Text = lblCertCode.Text.ToString();
                DateTime c = Convert.ToDateTime(lblCertDate.Text, System.Globalization.DateTimeFormatInfo.InvariantInfo);
                txtCertDateEdit.Text = c.ToString(SISInstall.CalenderDateFormat, System.Globalization.DateTimeFormatInfo.InvariantInfo);
                if (lblCertExpDate.Text != "")
                {
                    DateTime ced = Convert.ToDateTime(lblCertExpDate.Text, System.Globalization.DateTimeFormatInfo.InvariantInfo);
                    txtCertExpDateEdit.Text = ced.ToString(SISInstall.CalenderDateFormat, System.Globalization.DateTimeFormatInfo.InvariantInfo);
                }
                hdncertificateId.Value = hdncertid.Value;
                if (hdnPrimcert.Value != "")
                {
                    rbtnPrimCertEdit.Items.FindByValue(hdnPrimcert.Value.Trim()).Selected = true;
                }
                txtCertDescEdit.Text = lblCertDesc.Text;
                ModalPopupExtender1.Show();
            }
        }
    }   
    protected void btnUpdateCert_Click(object sender, EventArgs e)
    {
        SISInstall SISInstall = new SISInstall();
        try
        {
            string CertShortName = txtCerShrtNamEdit.Text;
            string CertName = txtCertFnameEdit.Text;
            string CertCode = txtCertCodeEdit.Text;
            DateTime cd = Convert.ToDateTime(txtCertDateEdit.Text, System.Globalization.DateTimeFormatInfo.InvariantInfo);
            DateTime ced = Convert.ToDateTime(txtCertExpDateEdit.Text, System.Globalization.DateTimeFormatInfo.InvariantInfo);
            //STABL.CertDate = txtCertDateEdit.Text.ToString();
            //STABL.CertExpirDate = txtCertExpDateEdit.Text.ToString();
            string CertDate = cd.ToString(SISInstall.CalenderDateFormat, System.Globalization.DateTimeFormatInfo.InvariantInfo);
            string CertExpirDate = ced.ToString(SISInstall.CalenderDateFormat, System.Globalization.DateTimeFormatInfo.InvariantInfo);
            string Primarycert = rbtnPrimCertEdit.SelectedItem.Value;
            string CertDescription = txtCertDescEdit.Text;
            string Certificateid = hdncertificateId.Value;
            int StaffId = Convert.ToInt32(hdnStfId.Value);
            if (Session["CertTable"] == null)
            {
                OpenSISWCFServiceStaffClient SPCClientPC = new OpenSISWCFServiceStaffClient();
                DataTable dtcertificate = SPCClientPC.PopulateCertification(StaffId);
                SPCClientPC.Close();

                dtcertificate.Columns.Add("tempid");
                //DataRow dr = dtcertificate.NewRow();
                for (int i = 0; i < dtcertificate.Rows.Count; i++)
                {
                    if (dtcertificate.Rows[i]["stf_cert_id"].ToString() == Certificateid)
                    {
                        dtcertificate.Rows[i]["tempid"] = "Edit";
                        dtcertificate.Rows[i]["stf_cert_exp_dt"] = Convert.ToDateTime(CertExpirDate.ToString());
                        dtcertificate.Rows[i]["stf_cert_short_nm"] = CertShortName;
                        dtcertificate.Rows[i]["stf_cert_desc"] = CertDescription;
                        dtcertificate.Rows[i]["stf_cert_dt"] = Convert.ToDateTime(CertDate.ToString());
                        dtcertificate.Rows[i]["stf_cert_nm"] = CertName;
                        dtcertificate.Rows[i]["stf_pri_cert_ind"] = Primarycert;
                        dtcertificate.Rows[i]["stf_cert_cd"] = CertCode;
                    }
                    //dtcertificate.Rows.Add(dr);
                }
                Session.Add("CertTable", dtcertificate);
            }
            else
            {
                DataTable dtcertificate = (DataTable)Session["CertTable"];
                //dtcertificate.Columns.Add("tempid");
                //DataRow dr = dtcertificate.NewRow();
                for (int i = 0; i < dtcertificate.Rows.Count; i++)
                {
                    if (dtcertificate.Rows[i]["stf_cert_id"].ToString() == Certificateid)
                    {
                        if (dtcertificate.Rows[i]["tempid"].ToString() != "Added")
                        {
                            dtcertificate.Rows[i]["tempid"] = "Edit";
                        }
                        dtcertificate.Rows[i]["stf_cert_exp_dt"] = Convert.ToDateTime(CertExpirDate.ToString());
                        dtcertificate.Rows[i]["stf_cert_short_nm"] = CertShortName;
                        dtcertificate.Rows[i]["stf_cert_desc"] = CertDescription;
                        dtcertificate.Rows[i]["stf_cert_dt"] = Convert.ToDateTime(CertDate.ToString());
                        dtcertificate.Rows[i]["stf_cert_nm"] = CertName;
                        dtcertificate.Rows[i]["stf_pri_cert_ind"] = Primarycert;
                        dtcertificate.Rows[i]["stf_cert_cd"] = CertCode;
                    }
                    //dtcertificate.Rows.Add(dr);
                }
                Session.Add("CertTable", dtcertificate);
            }
            DataTable dt = (DataTable)Session["CertTable"];
            gvCertficates.DataSource = dt;
            gvCertficates.DataBind();
        }
        catch (Exception ex)
        {
            string error = ex.ToString();
        }
    }
    protected void rbtnDisability_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (rbtnDisability.SelectedItem.Value == "N")
        {
            hdndisdesc.Value = txtDisDesc.Text;
            txtDisDesc.Text = "";
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Script", "document.getElementById('divDisability').style.display='none'", true);
        }
        else
        {
            txtDisDesc.Text = hdndisdesc.Value;
        }
    }
    private void ml_InitCulture()
    {
        if (Session["MLCulture"] != null && Session["MLUICulture"] != null)
        {
            String MLCultureName = (String)Session["MLCulture"];
            //sCulture = Session["MLCulture"].ToString();
            String MLUICultureName = (String)Session["MLUICulture"];

            if ((MLCultureName != null) && (MLCultureName.Length > 0))
            {
                Page.Culture = MLCultureName;
            }

            if ((MLUICultureName != null) && (MLUICultureName.Length > 0))
            {
                Page.UICulture = MLUICultureName;
            }
        }
    }
    protected override void InitializeCulture()
    {
        ml_InitCulture();
    }


}
